package jdk5.annotation;

import java.lang.reflect.Method;

// 利用注解完成代码测试
public class TestTool {
    public static void main(String[] args) {
        NuBug testObj = new NuBug();

        Class cls = testObj.getClass();

        Method[] methods = cls.getDeclaredMethods();

        StringBuilder log = new StringBuilder();
        int errorNum = 0;

        for (Method method : methods) {
            if (method.isAnnotationPresent(Check.class)) {
                method.setAccessible(true);

                try {
                    method.invoke(testObj, null);

                } catch (Exception e) {
                    errorNum++;

                    log.append(method.getName());
                    log.append("  error : ");
                    log.append(e.getCause().getClass().getSimpleName());
                    log.append("  , error message : ");
                    log.append(e.getMessage());
                    log.append("\n");

                }
            }
        }

        log.append(cls.getSimpleName());

        System.out.printf(log.toString());

    }
}
